<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('广告主列表')"/>
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            广告主ID：<input type="text" name="id"/>
                        </li>

                        <li>
                            账户名称：<input type="text" name="name"/>
                        </li>

                        <li>
                            联系邮箱：<input type="text" name="email"/>
                        </li>

                        <li>
                            &ensp;&ensp;联系人：<input type="text" name="contacter"/>
                        </li>

                        <li>
                            手机号码：<input type="text" name="phonenumber"/>
                        </li>
                        <li>
                            公司名称：<input type="text" name="company"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="dsp:advertiser:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="dsp:advertiser:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="dsp:advertiser:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="dsp:advertiser:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('dsp:advertiser:edit')}]];
    var removeFlag = [[${@permission.hasPermi('dsp:advertiser:remove')}]];
    // 广告主角色列表
    var roleList = [[${@dict.getType('dsp_advertiser_role')}]];
    // 状态列表
    var statusList = [[${@dict.getType('dsp_advertiser_status')}]];
    // 运营区域列表
    var areaList = [[${@dict.getType('dsp_run_area')}]];

    var prefix = ctx + "dsp/advertiser";


    /**
     * 列内容格式化处理
     * @param value
     * @param row
     * @param index
     * @param col
     * @returns {string}
     */
    function colFormatter(value, row, index, col) {
        var values = row[col];
        var span = document.createElement('span');
        span.setAttribute('title', values);
        span.innerHTML = row[col];
        return span.outerHTML;
    }


    /**
     * 列内容格式化处理
     * @param value
     * @param row
     * @param index
     * @param list
     * @returns {string}
     */
    function value2Label(value, row, index, list) {
        let label;
        for (var i in list) {
            if (list[i].dictValue == value) {
                label = list[i].dictLabel;
                break;
            }
        }
        return label;
    }

    /**
     * 描述列格式化输出
     * @param value
     * @param row
     * @param index
     * @returns {string}
     */
    function desFomatter(value, row, index) {
        return colFormatter(value, row, index, 'description');
    }


    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "广告主",
            search: false,
            showExport: false,
            fixedColumns: true,                         // 是否启用冻结列（左侧）
            fixedNumber: 1,                             // 列冻结的个数（左侧）
            // rightFixedColumns: false,                   // 是否启用冻结列（右侧）
            // rightFixedNumber: 0,                        // 列冻结的个数（右侧）
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '广告主账户ID',
                    sortable: true,
                    align: 'center'
                },
                {
                    field: 'name',
                    title: '广告主账户名称',
                    sortable: true,
                    width: 400,
                    class: 'colStyle',
                    formatter: function (value, row, index) {
                        return colFormatter(value, row, index, 'name');
                    }
                },
                {
                    field: 'password',
                    title: '账户密码',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'description',
                    title: '品牌描述',
                    sortable: false,
                    width: 400,
                    class: 'colStyle',
                    formatter: function (value, row, index) {
                        return colFormatter(value, row, index, 'description');
                    }
                },
                {
                    field: 'email',
                    title: '联系邮箱',
                    sortable: false
                },
                {
                    field: 'contacter',
                    title: '联系人',
                    sortable: false
                },
                {
                    field: 'phonenumber',
                    title: '手机号码',
                    sortable: false
                },
                {
                    field: 'role',
                    title: '角色',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return value2Label(value, row, index, roleList);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return value2Label(value, row, index, statusList);
                    }
                },
                {
                    field: 'telephone',
                    title: '固定电话',
                    sortable: false
                },
                {
                    field: 'address',
                    title: '地址',
                    sortable: false
                },
                {
                    field: 'licenseUrl',
                    title: '执照预览地址',
                    sortable: false,
                    visible: false
                },
                {
                    field: 'licenseNo',
                    title: '执照编号',
                    sortable: false
                },
                {
                    field: 'licenseProvince',
                    title: '执照省份',
                    sortable: true
                },
                {
                    field: 'licenseCity',
                    title: '执照城市',
                    sortable: false
                },
                {
                    field: 'company',
                    title: '公司名',
                    sortable: true
                },
                {
                    field: 'brand',
                    title: '经营类别',
                    sortable: false
                },
                {
                    field: 'promotionArea',
                    title: '运营区域',
                    sortable: false,
                    formatter: function (value, row, index) {
                        for (var i in areaList) {
                            if (areaList[i].dictValue == value) {
                                return areaList[i].dictLabel;
                            }
                        }
                    }
                },
                {
                    field: 'promotionCenterProvince',
                    title: '运营省份',
                    sortable: false
                },
                {
                    field: 'promotionCenterCity',
                    title: '运营城市',
                    sortable: false
                },
                {
                    field: 'firstIndustryName',
                    title: '一级行业名称',
                    sortable: false
                },
                {
                    field: 'secondIndustryName',
                    title: '二级行业名称',
                    sortable: true
                },
                {
                    field: 'reason',
                    title: '审核拒绝原因',
                    sortable: true,
                    width: 400,
                    class: 'colStyle',
                    formatter: function (value, row, index) {
                        return colFormatter(value, row, index, 'reason');
                    }
                },
                {
                    field: 'balance',
                    title: '账户总余额',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>